package com.ganmiao.web.portal.controller.sys;

import com.ganmiao.resp.CommonResultRes;
import com.ganmiao.resp.MobBaseRes;
import com.ganmiao.resp.PageResult;
import com.ganmiao.resp.ResponseCode;
import com.ganmiao.server.sys.dto.SysRoleDto;
import com.ganmiao.server.sys.entity.SysRole;
import com.ganmiao.server.sys.query.SysRoleQuery;
import com.ganmiao.server.sys.service.SysRoleService;
import com.ganmiao.server.sys.validated.Add;
import com.ganmiao.server.sys.validated.Delete;
import com.ganmiao.server.sys.validated.Update;
import com.ganmiao.server.sys.vo.SysRoleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 角色信息
 */
@Api(tags = "角色信息")
@Slf4j
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    //角色信息
    @Autowired
    private SysRoleService sysRoleService;

    /**
     * 新增角色信息
     *
     * @param sysRole
     * @return
     */
    @ApiOperation("新增角色信息")
    @PostMapping("/addSysRole")
    public MobBaseRes addSysRole(@RequestBody @Validated(Add.class) SysRoleDto sysRole) {
        return sysRoleService.addSysRole(sysRole) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "新增角色信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "新增角色信息失败");
    }

    /**
     * 启用/停用/删除角色信息
     *
     * @param sysRole
     * @return
     */
    @ApiOperation("启用/停用/删除角色信息")
    @PutMapping("/deleteSysRole")
    public MobBaseRes deleteSysRole(@RequestBody @Validated(Delete.class) SysRole sysRole) {
        return sysRoleService.deleteSysRole(sysRole) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "停用/删除信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "停用/删除信息失败");
    }

    /**
     * 修改角色信息
     *
     * @param sysRole
     * @return
     */
    @ApiOperation("修改角色信息")
    @PutMapping("/updateSysRole")
    public MobBaseRes updateSysRole(@RequestBody @Validated(Update.class) SysRoleDto sysRole) {
        return sysRoleService.updateSysRole(sysRole) ? new MobBaseRes(ResponseCode.SUCCESS.getCode(), "修改角色信息成功") : new MobBaseRes(ResponseCode.FAIL.getCode(), "修改角色信息失败");
    }

    /**
     * 获取角色信息 (分页)
     *
     * @param sysRoleQuery
     * @return
     */
    @ApiOperation("获取角色信息 (分页)")
    @GetMapping("/getSysRoleList")
    public CommonResultRes<PageResult<SysRole>> getSysRoleList(SysRoleQuery sysRoleQuery) {
        return new CommonResultRes<>(sysRoleService.getSysRoleList(sysRoleQuery));
    }

    /**
     * 获取角色信息 (详情)
     *
     * @param roleId
     * @return
     */
    @ApiOperation("获取角色信息 (详情)")
    @GetMapping("/getSysRole/{roleId}")
    public CommonResultRes<SysRoleVo> getSysRole(@Validated @PathVariable Integer roleId) {
        return new CommonResultRes<>(sysRoleService.getSysRole(roleId));
    }

}
